package com.lxm.enigma.algorithm;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @Author: Lys
 * @Date 2022/5/31
 * @Describe
 **/
public class AesAlgorithm implements Algorithm {

    private final ObjectMapper objectMapper;


    public AesAlgorithm() {
        this.objectMapper = new ObjectMapper();
    }

    @Override
    public String encipher(Object content, String key) throws Exception {
        if (content instanceof String) {
            return AesUtils.aesEncrypt(content.toString(), key);
        }
        String ori = objectMapper.writeValueAsString(content);
        return AesUtils.aesEncrypt(ori, key);
    }

    @Override
    public String decipher(Object content, String key) throws Exception {
        return AesUtils.aesDecrypt(content.toString(), key);
    }
}
